#ifndef __COMMUNICATION_CORE_H__
#define __COMMUNICATION_CORE_H__
#include <stdbool.h>

#include "communication.h"

enum {
	NONE = 0,
    COMM_SERVER_INIT,
    COMM_CLIENT_INIT,
	COMM_SEND,
	COMM_RECV,
};

struct communication_ops {
    int (*server_init_ops)(void);
    int (*send_data_ops)(int sendfd, char *data, uint16 length);
    int (*recv_data_ops)(int recvfd, char **data, uint16 *length);
    int (*analy_data_ops)(struct data_packet *p_data_packet, 
                          char *data, uint16 length);
    int (*package_data_ops)(struct data_packet *p_data_packet,
                            char **data, uint16 *length);
};

struct communication_data {
    int recvfd;
    int sendfd;
    struct data_packet send_data_packet;
    struct data_packet recv_data_packet;
};

struct communication_device {
    unsigned int cmd;
	void *arg;
};

struct communication_core {
    struct communication_data data;
    struct communication_ops ops;
    struct communication_device dev;
    int (*ioctl)(struct communication_device *dev,
                     unsigned int cmd, void *arg);
};


extern void communication_core_destory(struct communication_core *p_communication_core);
extern void communication_core_init(struct communication_core *p_communication_core);
extern void free_data_packet(struct data_packet *data);
extern void reset_data_packet(struct data_packet *data);
extern bool cpy_data_packet(struct data_packet *tar, 
                            struct data_packet *src);


#endif